package ru.evga.inse.core.domain.dict;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import ru.evga.inse.core.domain.BaseEntity;


@Entity
@Table(name = "street", uniqueConstraints = @UniqueConstraint(columnNames =
{
    "name", "city_id"
}))
public class Street
    extends BaseEntity
{
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "name")
    private String name;
    @NotNull
    @ManyToOne
    @JoinColumn(name = "city_id", nullable = false, updatable = true)
    private City city;

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public City getCity()
    {
        return city;
    }

    public void setCity(City city)
    {
        this.city = city;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if ((obj == null) || (obj.getClass() != this.getClass()))
        {
            return false;
        }
        Street other = (Street)obj;
        if (getName() == null)
        {
            return false;
        }
        else
        {
            if (!getName().equals(other.getName()))
            {
                return false;
            }
        }
        if (getCity() == null)
        {
            return false;
        }
        return getCity().equals(other.getCity());
    }

    @Override
    public int hashCode()
    {
        int hash = 7;
        hash = accumulateHashCode(hash, getName());
        hash = accumulateHashCode(hash, getCity());
        return hash;
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder(super.toString());
        sb.append(", name:").append(getName()).append(", city:").append(getCity());
        return sb.toString();
    }
}
